Source Code Viewer - Example 5 - FindGameListByNameContainsAction

package name.matthewgreet.example5.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import name.matthewgreet.example5.common.AbstractFormDrivenActionSupport;
import name.matthewgreet.example5.common.ListCache;
import name.matthewgreet.example5.common.ListFinder;
import name.matthewgreet.example5.common.NA;
import name.matthewgreet.example5.dto.GameDTO;
import name.matthewgreet.example5.form.GameNameContainsForm;
import name.matthewgreet.example5.model.GameTable;
import name.matthewgreet.example5.model.Model;
import name.matthewgreet.example5.util.GameCompositeCache;

/**
 * Finds board games by overall ranking or ranking of a category.  
 */
@InterceptorRef("FormDrivenStack")
@Results({
	@Result(name=ActionSupport.INPUT, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"}),
	@Result(name=ActionSupport.SUCCESS, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"})
})
public class FindGameListByNameContainsAction extends AbstractFormDrivenActionSupport<GameNameContainsForm> {
	public static class GameListFinderByNameContains implements ListFinder<NA,GameDTO> {
		private static final long serialVersionUID = 6409312894523453002L;
		
		private String nameContains;
		
		public GameListFinderByNameContains(String nameContains) {
			this.nameContains = nameContains;
		}

		@Override
		public List<GameDTO> getList(NA selectedMaster) throws Exception {
			GameTable gameTable;
			
			gameTable = Model.getInstance().getGameTable();
			return gameTable.findByNameContains(nameContains);
		}
		
		public String getNameContains() {
			return nameContains;
		}

	}
	
	
	private static final long serialVersionUID = -7979376337555804889L;
	
    @Action("/FindGameListByNameContains")
    @Override
    public String execute() throws Exception {
    	GameNameContainsForm form;
    	ListCache<NA,Integer,GameDTO> listCache;
    	HttpSession session;
    	
    	form = getModel();
    	
    	session = getRequest().getSession();
    	listCache = GameCompositeCache.getInstance(session).getMasterListCache();
    	listCache.setBaseRecordListFinder(new GameListFinderByNameContains(form.getNameContains()));
		
		return SUCCESS;
    }

	@Override
	protected GameNameContainsForm makeForm() {
		return new GameNameContainsForm();
	}

}